// <copyright file="DeleteLinkExtension.cs" company="Clever Software">
// Copyright (c) 2013, 2014 All Right Reserved, http://www.cleversoftware.by
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Clever Software</author>
// <email>info@cleversoftware.by</email>
// <date>2014-02-04</date> 
// <summary>CleverCMS source code</summary>

namespace CleverCMS.Core.Web.Extensions
{
    using System.Collections.Generic;
    using System.Web.Mvc;
    using System.Web.Mvc.Html;
    using System.Web.Routing;

    public static class DeleteLinkExtension
    {
        public static MvcHtmlString DeleteLink(this HtmlHelper helper, string text, string action, string controller,
                                               object routeValues,
                                               object htmlAttributes)
        {
            return DeleteLink(helper, text, action, controller, new RouteValueDictionary(routeValues),
                              new RouteValueDictionary(htmlAttributes));
        }

        public static MvcHtmlString DeleteLink(this HtmlHelper helper, string text, string action, string controller,
                                               RouteValueDictionary routeValues,
                                               IDictionary<string, object> htmlAttributes)
        {
            if (htmlAttributes != null && !htmlAttributes.ContainsKey("onclick"))
            {
                htmlAttributes.Add("onclick", "deletePost(this.href); return false;");
            }

            return helper.ActionLink(text, action, controller, routeValues, htmlAttributes);
        }
    }
}